﻿<link href="@Url.Content("~/Content/Style.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/knockout-1.2.1.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/knockout.mapping.js")" type="text/javascript"></script>
<div id="openid-login">
	<h2>Sign In using OpenID</h2>
	<span id="openid-message">@ViewBag.Message</span>
	<p>Please click your account provider:</p>
	<div id="provider-img">
		<a href="#" id="google-provider"><img src="../../Content/images/google-enabled.png" alt="Sign in with Google"/></a>
		<a href="#" id="yahoo-provider"><img src="../../Content/images/yahoo-enabled.png" alt="Sign in with Yahoo"/></a>
	</div>
</div>

<script type="text/javascript">
    var google_provider = 'https://www.google.com/accounts/o8/id';
    var yahoo_provider = 'https://me.yahoo.com';
    $("#google-provider").click(function () {
        $.ajax({
            url: '@Url.Action("Authenticate", "Account", new { returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]) })',
            type: 'POST',
            data: ko.toJSON({ returnUrl: window.location.href, provider: google_provider }),
            dataType: 'json',
            contentType: 'APPLICATION/JSON',
            success: function (result) {
                if (result.Success) {
                    window.location.href = result.RedirectUrl;
                }
                if (!result.Success) {
                    $('#openid-message').text(result.Message);
                }
            }
        });
    });
    $("#yahoo-provider").click(function () {
        $.ajax({
            url: '@Url.Action("Authenticate", "Account", new { returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]) })',
            type: 'POST',
            data: ko.toJSON({ returnUrl: window.location.href, provider: yahoo_provider }),
            dataType: 'json',
            contentType: 'APPLICATION/JSON',
            success: function (result) {
                if (result.Success) {
                    window.location.href = result.RedirectUrl;
                }
                if (!result.Success) {
                    $('#openid-message').text(result.Message);
                }
            }
        });
    });
</script>